﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>每日信息输入</title>
    <link rel="stylesheet" type="text/css" href="/easyui/themes/default/easyui.css"/>
	<link rel="stylesheet" type="text/css" href="/easyui/themes/icon.css"/>
	<link rel="stylesheet" type="text/css" href="/content/style.css"/>
    <script type="text/javascript" src="/easyui/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="/easyui/jquery.easyui.min.js"></script>
</head>
<body>
   <script type="text/javascript">
       $(function () {
           $("#datagrid").datagrid({
               'onDblClickRow': function (index, field, value) {
                   editLevel(index);
               },
               url: '/Admin/Item/GetListByPage/',
               queryParams: { type: '@ViewData["type"]' },
               fitColumns: true,
               striped: true,
               pagePosition: 'both',
               loadMsg: '数据正在加载,请稍等...',
               pagination: true,
               rownumbers: true,
               singleSelect: false,
               checkbox: true,
               idField: "ID",
               checkOnSelect: true,
               pageList: [5, 10, 15, 20],
               toolbar: [{
                   id: 'btnadd',
                   text: '添加',
                   iconCls: 'icon-add',
                   handler: function () {
                       AddNew();
                   }
               }, '-', {
                   id: 'btndel',
                   text: '删除',
                   iconCls: 'icon-remove',
                   handler: function () {
                       removeLevel();

                   }
               }, '-', {
                   id: 'btndels',
                   text: '批量删除',
                   iconCls: 'icon-remove',
                   handler: function () {
                       deletes();
                   }
               }, '-', {
                   id: 'btnEdit',
                   text: '编辑',

                   iconCls: 'icon-edit',
                   handler: function () {
                       editLevel();
                   }
               }],
               idField: 'ID',
               columns: [[
    { field: 'CheckID', title: '选择', rowspan: 2, width: 80, checkbox: true },
    { field: 'ID', title: '序号', rowspan: 2, width: 20,align:'center' },
    { field: 'Type', title: '类型', width: 20, align: 'center',
        formatter: function (value, row, index) {
            if (value == 1) {
                return "汽车";
            }
            return "挖机";
        }
    },
    { field: 'CarID', title: '上层汽车ID', rowspan: 2, width: 40,align:'center' },
    { field: 'CarNumber', title: '汽车编号', width: 40, align: 'center' },
    { field: 'times', title: '趟数', width: 20, align: 'center' },
    { field: 'CreateDate', title: '添加时间', width: 80, align: 'left',
        formatter: function (value, row, index) {
            return eval("new " + value.substr(1, value.length - 2)).toLocaleDateString();
        }
    }]]

           });
       });
    function AddNew() {
        $('#dlg').dialog('open').dialog('setTitle','编辑车辆信息');
	    $('#fmlevel').form('load','/admin/item/create/'+'@ViewData["type"]');
		url = '/admin/item/create/';
    }
    function SaveCar() {
        $('#fmlevel').form('submit', {
            url: url,
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (result) {
                var result = eval('(' + result + ')');
                if (result.success) {
                    $('#dlg').dialog('close'); 	// close the dialog
                    $('#datagrid').datagrid('reload'); // reload the user data
                    $.messager.show({	// show error message
                                title: '提示！',
                                msg: result.msg
                            });
                } else {
                    $.messager.show({
                        title: 'Error',
                        msg: result.msg
                    });
                }
            }
        });
    }
  function deletes(){
        var rows = $('#datagrid').datagrid('getSelections');

        if (!rows || rows.length == 0) {
            $.messager.alert("错误提示","没有选择删除的项","warning");
            return;
        }
        var parm="";
        $.each(rows,function(index,value){
            if (index == 0) 
            {
                parm = "idlist="+value.ID;    
            }
            else
            {
                parm +="&idlist="+value.ID;
            }
        });
        $.messager.confirm('确认', '你确定要删除吗?', function (r){
            if (r) {
                $.ajax({
            type:'POST',
            url:"/admin/item/Deletes",
            data:parm,
            success:function(result){
                if (result.success) {                    
                    $("#datagrid").datagrid("reload");
                    $.messager.show({	// show error message
                                title: '提示！',
                                msg: result.msg
                            });   
                 }else {
                    $.messager.alert("错误提示",result.msg,'error');   
                  }
            }

        });
            }
        });
        
    }
    function removeLevel() {
        var row = $('#datagrid').datagrid('getSelected');
        if (!row) {
            $.messager.alert("错误提示", "没有选择要删除的项", 'warning');

            return;
        }
        if (row) {
            $.messager.confirm('确认', '你确定要删除吗?', function (r) {
                if (r) {
                    $.post('/admin/item/delete', { id: row.ID }, function (result) {
                        if (result.success) {
                            //$.messager.alert(result.msg,row.ID);
                            $('#datagrid').datagrid('reload'); // reload the user data
                            $.messager.show({	// show error message
                                title: '提示！',
                                msg: result.msg
                            });
                        } else {
                            $.messager.show({	// show error message
                                title: 'Error',
                                msg: result.msg
                            });
                        }
                    }, 'json');
                }
            });
        }
    }
    
    function editLevel(index){            
            var obj = $('#datagrid');
            if (index) {
                obj.datagrid("clearSelections");
                obj.datagrid('selectRow',index);
            }            
			var row = obj.datagrid('getSelected');
			if (row){
				$('#dlg').dialog('open').dialog('setTitle','编辑层信息');
				$('#fmlevel').form('load','/admin/item/Edit/'+row.ID);
                $('#fmlevel').form({
                    'onLoadSuccess':function(data){
                        $("#PID").select(data.Name);
                    }
                });
                //alert(row.ID);
				url = '/admin/item/Edit/';
			}
            else
            {
                $.messager.alert("提示信息","没有选择操作数据");
            }
		}
    
   </script>
    <div id="datagrid">  
    </div>
    <div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"  
        closed="true" buttons="#dlg-buttons"> 
        @Html.Partial("Create")
<div id="dlg-buttons">  
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="SaveCar()">Save</a>  
    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">Cancel</a>  
</div>
</div> 
</body>
</html>
